1. /* slffctpf.cpp by K.Tsuru */
  2. // function ID 2009 DRADIX since ver 2.181
  3. /***********************************************************
  4. N!(N >= 5)
  5. factorial by prime factorization method and tournament product
  6. refer to GMP's factorial algorithm using prime factorization
  7. But the recursive call is not used such as the typical example
  8. of binary splitting method.
  9. Nov 26 2016
  10. timing(sec)
  11. N | FactPF figures
  12. 10^5 | 0.12 456,574
  13. 2*10^6 | 3.40 11,733,475 ... exclude fftMaxArraySize = 2^20 =1,048,576
  14. 2*10^7 | 76.84 137,334,715 FFTUsedTimes() = 160650
  15. 1000003(a prime number) 1.51
  16. ***********************************************************/
  17. #ifndef SN_H
  18. #include "sn.h"
  19. #endif
  20. /*********************************************
  21. For pull out the power of 10
  22. 2^p * 5^q ==> 2^(p-q) * 10^q (of course p > q)
  23. **********************************************/
  24. const int POS2 = 0; // position of "2" in {2,3,5,7,....}
  25. const int POS5 = 2; // position of "5" in {2,3,5,7,....}
  26. SLong FactPF(ulong N) {
  27. if(N <= 20) return factD(N); // since version 2.30
  28. SNBlock<primeFactor> pf;
  29. int npf = FactorialIntoPrimeFactor(N, pf);// 'npf' is the number of prime factor
  30. int pow10 = pf[POS5].power; // the power of 10
  31. pf[POS2].power -= pow10; // reduce the power of 2
  32. // exclude "5"
  33. npf--;
  34. int i;
  35. for(i = POS5; i < npf; i++) pf[i] = pf[i+1]; // Default assignment operator is used for the structure "primeFactor".
  36. pf[i].power = pf[i].prime = 0;
  37. SLong Q = PrimeFactorProduct(pf, npf);
  38. Q.MultPow10(pow10); // Q*10^pow10 in which shifting array elements is used.
  39. return Q;
  40. }

slffctpf.cpp : last modifiled at 2016/12/26 15:35:59(1,645 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).